//
//  OneKeyRepairUploadImageCollectionCell.m
//  customer
//
//  Created by Holothurian on 2018/11/3.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "OneKeyRepairUploadImageCollectionCell.h"

@implementation OneKeyRepairUploadImageCollectionCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
        _imgView.userInteractionEnabled = YES;
        [self.contentView addSubview:_imgView];
        
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteBtn.frame = CGRectMake(60, 0, 20, 20);
        _deleteBtn.layer.cornerRadius = 10;
        _deleteBtn.layer.masksToBounds = YES;
        [_deleteBtn setImage:[UIImage imageNamed:@"oneKeyRepairDelete"] forState:UIControlStateNormal];
        [_deleteBtn setImage:[UIImage imageNamed:@"oneKeyRepairDelete"] forState:UIControlStateSelected];
        [_deleteBtn setBackgroundColor:[UIColor lightGrayColor]];
        [_deleteBtn addTarget:self action:@selector(deleteButtonEvent) forControlEvents:UIControlEventTouchUpInside];
        [_imgView addSubview:_deleteBtn];
        
        _placeholderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
        _placeholderView.backgroundColor = [UIColor backGroudColorForView];
        _placeholderView.userInteractionEnabled = YES;
        [self.contentView addSubview:_placeholderView];;
        
        _placeholderImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"repairUploadImage"]];
        _placeholderImgView.frame = CGRectMake(20, 10, 40, 30);
        _placeholderImgView.contentMode = UIViewContentModeScaleAspectFit;
        _placeholderImgView.userInteractionEnabled = YES;
        [_placeholderView addSubview:_placeholderImgView];
        
        _uploadLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 45, 80, 35)];
        _uploadLabel.text = @"上传凭证\n最多6张";
        _uploadLabel.textColor = RGBColor(153, 153, 153);
        _uploadLabel.font = Font(12);
        _uploadLabel.numberOfLines = 0;
        _uploadLabel.textAlignment = NSTextAlignmentCenter;
        _uploadLabel.userInteractionEnabled = YES;
        [_placeholderView addSubview:_uploadLabel];
        UITapGestureRecognizer *tapAdd = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapToAddImage)];
        [_placeholderView addGestureRecognizer:tapAdd];
        
        UITapGestureRecognizer *tapHaveALook = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHaveALookImage)];
        [_imgView addGestureRecognizer:tapHaveALook];
    }
    return self;
}

- (void)tapToAddImage{
    if ([self.delegate respondsToSelector:@selector(uploadRepairImageCollectionCellAddImage:)]) {
        [self.delegate uploadRepairImageCollectionCellAddImage:self.indexPath];
    }
}

- (void)tapHaveALookImage{
    if ([self.delegate respondsToSelector:@selector(uploadRepairImageCollectionCellTapHaveALook:)]) {
        [self.delegate uploadRepairImageCollectionCellTapHaveALook:self.indexPath];
    }
}

- (void)deleteButtonEvent{
    if ([self.delegate respondsToSelector:@selector(uploadRepairImageCollectionCellDeleteImage:)]) {
        [self.delegate uploadRepairImageCollectionCellDeleteImage:self.indexPath];
    }
}

@end
